package com.moon.synthesis.utils.excel_poi;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.moon.synthesis.utils.excel_poi.sheets.ExportMoreView;
import com.moon.synthesis.utils.excel_poi.sheets.ExportView;
import com.moon.synthesis.utils.excel_poi.sheets.MyExcelPoiUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;

import java.util.ArrayList;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Slf4j
public class ExcelBean {

    @Excel(name = "编号", width = 20)
    private String id;
    @Excel(name = "用户名", width = 20)
    private String username;
    @Excel(name = "手机号", width = 30)
    private String phone;
    @Excel(name = "备注", width = 50)
    private String remark;

    public static void main(String[] args) {
        // 测试导出
        new ExcelBean().singleSheet();

    }

    // 单sheet
    private void singleSheet() {
        try {
            List<ExcelBean> list = new ArrayList<>();
            Workbook workbook = MyExcelPoiUtils.getWorkbook("单sheet导出", "这是一个sheet页", ExcelBean.class, list);
        } catch (Exception e) {
            log.error("error: " + e.getMessage());
        }
    }

    // 多sheet
    private void moreSheet() {
        try {
            List<ExcelBean> sheetList1 = new ArrayList<>();
            List<ExcelBean> sheetList2 = new ArrayList<>();
            ExportView sheet1 = new ExportView(new ExportParams("标题1", "第一个sheet页名称"), sheetList1, ExcelBean.class);
            ExportView sheet2 = new ExportView(new ExportParams("标题2", "第二个sheet页名称"), sheetList2, ExcelBean.class);
            List<ExportView> moreViewList = new ArrayList<>();
            moreViewList.add(sheet1);
            moreViewList.add(sheet2);
            ExportMoreView exportMoreView = new ExportMoreView();
            exportMoreView.setMoreViewList(moreViewList);
            Workbook workbook = MyExcelPoiUtils.getWorkbook(ExcelType.HSSF, exportMoreView);
        } catch (Exception e) {
            log.error("error: " + e.getMessage());
        }

    }
}
